<html>
<head>
	<meta charset="UTF-8"/>
	<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
	<title>吃货餐厅</title>
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.5/themes/metro/easyui.css"/>
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.5/themes/mobile.css"/>
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.5/themes/icon.css"/>
	<script type="text/javascript" src="js/jquery-easyui-1.5/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery-easyui-1.5/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="js/jquery-easyui-1.5/jquery.easyui.mobile.js"></script>
    <style type="text/css">
	.RED
	{
		background: #eee;
	}
	
	.bg
	{
	 	background: #E6E6E6;
	}
</style>

    <script type="text/javascript">
	 /*<![CDATA[*/ 
	            
	 
	$(document).ready(  
			  function(){   
				  
				  $("#chatbtn").textbox({onClickButton:function(e){
					  	var text = $("#chatbtn").val();
						 if(text.length==0)
							 return;
						
						 var name = encodeURIComponent(text);
						
						  var url = "p_getFoodByLike?foodname="+name;
						  $.get(url, function(data){
							  $("#chatdiv").empty();
							  if(data.length==0)
							  {
								  $("#chatdiv").html('<center><span style="color: #9d9d9d;font-size: 30px;">无查询记录！</span></center>');
								  $("#chatbtn").textbox("setValue", "");
								  return;
							  }
							  $.each( data, function(index, item)
									  {
										  var content="<div>";
										  content=content+'<table border="1"  width="100%" style="border-style: solid;border-width: 0 0 1px 0;border-color: #ddd;">';
						          	 		
										  content=content+'<tr>';
										  content=content+'<td style="border: none;" width="50%" height="100px" ><img width="100%" height="100%" src="/myres/'+item.image+'"/></td>';
										  content=content+'<td style="border: none;" width="50%"  >';
										  content=content+'<table width="100%" >';
										  content=content+'<tr><td style="border: none;"><span style="font-size: 23px;font-family:\'微软雅黑\';">'+item.foodname+'</span></td><td align="right" onclick="addCar(\''+item.id+'\')"><img src="img/add.jpg" width="20px" height="20px"/>&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>';
										  content=content+'<tr><td style="border: none;"><span style="font-size: 20px;color: #009900;font-family:\'微软雅黑\';" >'+item.price+'&nbsp;元</span></td></tr>';
										  content=content+'<tr><td style="border: none;" name="tdclick" onclick="stop(this)">';
										  content=content+'<div  onclick="stop()"><input id="'+item.id+'_input" class="easyui-numberspinner" value="1" data-options="min:1" style="width:81px;"/></div>';
										  content=content+'</td></tr>';
										  content=content+'</table>';
										  content=content+'</td>';
										  content=content+'</tr>';
										  content=content+'</table>';
										  content=content+'</div>';
										  
										  $("#chatdiv").append(content); 
										  $.parser.parse();
									  });
							  $("#chatbtn").textbox("setValue", "");
							  
						  });

					  }});		 
								
				clear();
	 });
	 
	 function stop(e)
	 {
		 stopBubble(e);
	 }
	 
	function stopBubble(e) { 
		//如果提供了事件对象，则这是一个非IE浏览器 
		if ( e && e.stopPropagation ) 
		    //因此它支持W3C的stopPropagation()方法 
		    e.stopPropagation(); 
		else
		    //否则，我们需要使用IE的方式来取消事件冒泡 
		    window.event.cancelBubble = true; 
	}
	 
	

	function show(obj) 
	{
		$(obj).removeClass('bg');
	} 
	
	function removeClass(obj) 
	{
		$(obj).removeClass('RED');
	} 

	 
	 function showred(obj) 
		{
			$(obj).removeClass('RED');
		} 
	 
	 function action(obj)
	 {
		         $(obj).toggleClass('RED');
		         setTimeout(function(){showred(obj);}, 100);
	 }
	
	 function showChat(obj)
	 {
		 
		 $(obj).toggleClass('RED');
         setTimeout(function(){removeClass(obj);}, 100);
         
         var deskid=$("#deskid").val();
         
         var url ="p_showChat?&deskid="+deskid;
 		 window.location.href=url;
	 }
	 
	 function actionFirst(obj)
	 {
		         $(obj).toggleClass('RED');
		         setTimeout(function(){removeClass(obj);}, 100);
		         
		         history.go(-1);
	 }
	 
	 function clear()
	 {
		 $("#chatbtn").textbox("setValue", "");
		 $('#chatbtn').textbox('textbox').focus();
	 }
	 
	 function addCar(foodid)
	 {
		  var deskid=$('#deskid').val();
		  var count="#"+foodid+"_input";
		  var num = $(count).val();
		  var url = "add_order?foodid="+foodid+"&deskid="+deskid+"&count="+num;
		  
		  $.ajax(
		 			{
		 	        	url: url,
		 	        	async: false,//改为同步方式
		 	        	type: "GET",
		 	        	success: function (data) {
		 	        		if(data=='failed')
							  {
							  		$('#dlg1').dialog('open').dialog('center');
							  		
							  }else
							  {
								  var url ="p_showCar?&deskid="+deskid;
							 		 window.location.href=url;
							  }
		 	 			}
		 	 	});
	 }
	/*]]>*/  
	</script>


</head>
<body>
	<div class="easyui-navpanel">
	
        <header>               
                <input class="easyui-textbox"  id="chatbtn" style="width:100%;height:100%;"  data-options="prompt:'请 输 入菜品名',buttonText:'&nbsp;查 &nbsp;询 &nbsp;'"/>
        </header>
		
        <div id="chatdiv" style="overflow:hidden;width:100%;padding:5px;"></div> 
        
        <div id="dlg1" class="easyui-dialog" style="padding:20px 6px;width:80%;" data-options="inline:true,modal:true,closed:true,title:'提示'">
			<center><div>您已下单如需帮助请联系客服!</div></center>
			<div class="dialog-button">
				<a href="javascript:void(0)" class="easyui-linkbutton" style="width:100%;height:35px" onclick="$('#dlg1').dialog('close')">确定</a>
			</div>
	</div>
	
	</div>
	<input  id="deskid" type="hidden" th:value="${deskid}" />
	
</body>
</html>